﻿using System;
using System.IO;
using System.Web;
using System.Xml;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Web.UI;
using LTJ.Config;
using LTJ.Common;
using LTJ.Common.XML;

namespace uswinweb.datacontrol
{
    public partial class mainmenulist : BaseWebControl
    {
        public override void ShowUserControl()
        {
            string configPath = Utils.GetMapPath(BaseConfigs.GetSitePath.ToLower() + "config/adminmenu.config");
            XmlDocumentExtender doc = new XmlDocumentExtender();
            doc.Load(configPath);
            XmlNodeList mainmenus = doc.SelectNodes("/dataset/mainmenu");
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("id"));
            dt.Columns.Add(new DataColumn("menuid"));
            dt.Columns.Add(new DataColumn("title"));
            dt.Columns.Add(new DataColumn("defaulturl"));
            dt.Columns.Add(new DataColumn("etitle"));
            dt.Columns.Add(new DataColumn("delitem"));
            foreach (XmlNode subMenuItem in mainmenus)
            {
                DataRow dr = dt.NewRow();
                dr["id"] = subMenuItem["id"].InnerText;
                dr["menuid"] = subMenuItem["menuid"].InnerText;
                dr["title"] = subMenuItem["menutitle"].InnerText;
                dr["defaulturl"] = subMenuItem["pagename"].InnerText;
                dr["etitle"] = subMenuItem["englishname"].InnerText;
                if (FindSubMenuItem(subMenuItem["menuid"].InnerText, doc))
                    dr["delitem"] = "删除";
                else
                    dr["delitem"] = "<a class=\"l_blue\" href='mainmenu_set.aspx?mode=del&menuid=" + subMenuItem["menuid"].InnerText + "' onclick='return confirm(\"您确认要删除此菜单项吗?\")'>删除</a>";
                dt.Rows.Add(dr);
            }

            dataDT = dt;
            GetPageList("");
        }


        private bool FindSubMenuItem(string menuid, XmlDocumentExtender doc)
        {
            XmlNodeList submenuitem = doc.SelectNodes("/dataset/submain");
            foreach (XmlNode item in submenuitem)
            {
                if (item["menuparentid"].InnerText == menuid)
                    return true;
            }
            return false;
        }
    }
}